#!/bin/bash
#
# Generate changes file from OpenVINO Debian binary packages.
#
# To upload packages to mini-dinstall repository, changes is necessary.
# But I can not find a tool to generate changes from binary packages,
# so create this script to generate it.

OPENVINO_VERSION="2018R4"

echo "Format: 1.8"
echo "Date: Sat, 01 Dec 2018 12:00:00 +0800"
echo "Source: openvino"
echo -e "Binary:\c"
for i in $(ls | grep ".deb$"); do
    dpkg-deb --showformat=' ${Package}' --show $i
done
echo ""
echo "Architecture: amd64"
echo "Version: 2018.4-421"
echo "Distribution: xenial"
echo "Urgency: medium"
echo "Maintainer: Bofu Chen (bafu) <bofu@dt42.io>"
echo "Changed-By: Bofu Chen (bafu) <bofu@dt42.io>"
echo "Description:"
for i in $(ls | grep ".deb$"); do
    dpkg-deb --showformat=' ${Package} - ${binary:Summary}\n' --show $i
done
echo "Changes:"
echo " openvino (2018.4-421) unstable; urgency=medium"
echo " ."
echo "   * Converted from rpm to deb manually."
echo "Checksums-Sha1:"
for i in $(ls | grep ".deb$"); do
    sha1sum=$(sha1sum $i | awk {'print $1'})
    size=$(stat --printf="%s" $i)
    package=$i
    echo " $sha1sum $size $package"
done
echo "Checksums-Sha256:"
for i in $(ls | grep ".deb$"); do
    sha256sum=$(sha256sum $i | awk {'print $1'})
    size=$(stat --printf="%s" $i)
    package=$i
    echo " $sha256sum $size $package"
done
echo "Files:"
for i in $(ls | grep ".deb$"); do
    md5sum=$(md5sum $i | awk {'print $1'})
    size=$(stat --printf="%s" $i)
    section=$(dpkg-deb --showformat='${Section}' --show $i)
    priority=$(dpkg-deb --showformat='${Priority}' --show $i)
    package=$i
    echo " $md5sum $size $section $priority $package"
done
